<script language="javascript" type="text/javascript">       
    addTab("<?php echo Core_Util::escapeForJS($this->store->getName());?>",'<?php echo $this->url(array('action' => 'list'))?>');
</script>
<table border="0" class="bread-crumb">
	<tr>
		<td ><?php echo $this->partial('breadcrum-menu.phtml', array('new_orders' => $this->new_orders, 'id_store' => $this->store->id)) ?></td>
        <td style="text-align: right;">
			<a class="underline non_space" href="<?php echo $this->url(array('module' => 'store','controller' => 'product', 'action' => 'create', 'id_store' => $this->store->id), null, true); ?>">
				<img src="img/add.png" class="bordernone" height="11" width="11" /><?php echo $this->translate('NEW_PRODUCT_LABEL') ?>
			</a>
		</td>
	</tr>
</table>
<?php echo $this->partial("displayErrorMessages.phtml", array('error_messages' => $this->error_messages)); ?>

<?php 
//    $this->form_search->setAction($this->url(array('action' => 'list', 'keyword' => null, 'status' => null, 'page' => null)));
//    echo $this->form_search; 
?>
<?php if(isset($this->extra_values['search_params']['keyword']) || isset($this->extra_values['search_params']['status'])):?>
<div class="title_search_result">
    <?php 
        $total_rows = $this->paginator->getTotalItemCount();
        if($total_rows > 1):
            echo sprintf($this->translate('FOUND_RESULTS'), $total_rows );
        else:
            echo sprintf($this->translate('FOUND_RESULT'), $total_rows );
        endif;
        
        if(!empty($this->extra_values['search_params']['date_from'])):
            echo sprintf($this->translate('FOUND_FROM_DATE_FROM'), $this->escape($this->extra_values['search_params']['date_from']));
        endif;
        
         if(!empty($this->extra_values['search_params']['date_to'])):
            echo sprintf($this->translate('FOUND_FROM_DATE_TO'), $this->escape($this->extra_values['search_params']['date_to']));
        endif;
        
        if(!empty($this->extra_values['search_params']['status']) && $this->extra_values['search_params']['status'] != Core_Model_DbTable_Carts::STATUS_DEFAULT_SEARCH):
            $listStatus = Core_Model_DbTable_Carts::getListStatus();
            echo sprintf($this->translate('FOUND_WITH_STATUS'),  $listStatus[$this->extra_values['search_params']['status']]);
        endif;
    ?>
    - <a id="reset" href="<?php echo $this->url(array('keyword' => null, 'status' => null, 'page' => null)); ?>"><?php echo $this->translate('FOUND_RESET')?></a>
</div>
<?php endif;?>
<?php 
    if(count($this->paginator)):
?>
<?php echo $this->partial("markListMessages.phtml", array('extra_values' => $this->extra_values));?>

<script type="text/javascript">
    function getMessage(message){
        $(".msg_panel").remove();
        return '<div class="msg_panel"><p>' + message + '</p></div>';
    }
    $(document).ready(function(){
        $(".mark_important").click(function(){
            var url = $(this).attr("rel");
            var tooltip_important = "<?php echo $this->translate('TOOLTIP_STATUS_IMPORTANT')?>";
            var tooltip_unimportant = "<?php echo $this->translate('TOOLTIP_STATUS_UNIMPORTANT')?>";
            $.ajax({
                url: url,
                data: {},
                success: $.proxy(function(respond){
                    var result = jQuery.parseJSON(respond);
                    if(result.success == true){
                        $(this).attr('rel', result.rel);
                        if(result.is_important == true){
                            $(this).removeClass("order_unimportant");
                            $(this).addClass("order_important");
                            $(this).attr('title', tooltip_unimportant);
                        }
                        else{
                            $(this).removeClass("order_important");
                            $(this).addClass("order_unimportant");
                            $(this).attr('title', tooltip_important);
                        }
                    }
                    $(".carts_control").before(getMessage(result.message));
                },this)
            });
        });
    });
</script>

<table class="tbl_list_carts" id="list_carts">
    <thead>
        <tr>
            <th style="width: 20px;">
                <span class="check_all_entry"><input type="checkbox" name="chx_carts" id="chx_carts" value="1"></span>
            </th>
            <th style="width: 140px;">
                <span><?php echo $this->translate('HEADER_ORDER_ID');?></span>
            </th>
            <th style="width: 220px;">
                <span><?php echo $this->translate('HEADER_BUYER_NAME');?></span>
            </th>
            <th style="width: 100px;">
                <span class="align_center"><?php echo $this->translate('HEADER_ORDER_DATE');?></span>
            </th>
            <th style="width: 150px;">
                <span class="align_right"><?php echo $this->translate('HEADER_TOTAL_PAYMENT');?></span>
            </th>
            <th style="width:90px;">
                <span class="align_center"><?php echo $this->translate('HEADER_ACTION');?></span>
            </th>
        </tr>
    </thead>
    <tbody>
        <?php foreach($this->paginator as $cart):?>
        <tr class="<?php 
                        if($cart['status'] == Core_Model_DbTable_Carts::STATUS_UNREAD) echo "order_unread"; 
                        else if ($cart['status'] == Core_Model_DbTable_Carts::STATUS_READ) echo "order_read";
                        else if ($cart['status'] == Core_Model_DbTable_Carts::STATUS_RESOLVED) echo "order_resolved"
                   ?>">
            <td class="check_cart">
                <input class="cbx_cart" type="checkbox" name="entry" value="<?php echo $cart->id;?>">
            </td>
            <td class="cart_id">
                <div class="order_info">
                    <?php if($cart->is_important == Core_Model_DbTable_Carts::STATUS_IMPORTANT):?>
                        <a class="order_important mark_important" title="<?php echo $this->translate('TOOLTIP_STATUS_UNIMPORTANT')?>"
                           rel="<?php echo $this->url(array('action' => 'important', 'id' => $cart->id, 'is_important' => Core_Model_DbTable_Carts::STATUS_UNIMPORTANT))?>"></a>
                    <?php else:?>
                        <a class="order_unimportant mark_important" title="<?php echo $this->translate('TOOLTIP_STATUS_IMPORTANT')?>"
                           rel="<?php echo $this->url(array('action' => 'important', 'id' => $cart->id, 'is_important' => Core_Model_DbTable_Carts::STATUS_IMPORTANT))?>"></a>
                    <?php endif;?>
                    
                    <span class="order_status <?php echo ($cart->status == Core_Model_DbTable_Carts::STATUS_RESOLVED)?"order_resolved":"";?>"></span>
                    <a class="order_id" href="<?php echo $this->url(array_merge(array('action' => 'detail', 'id' => $cart->id), $this->extra_values['search_params']));?>">
                        <?php echo 'Order #' . $this->escape($cart->id)?>
                    </a>
                </div>
            </td>
            <td>
                <div class="order_info">
                    <?php if(!empty($cart->link)):?>
                        <a class="order_name" target="_blank" href="<?php echo $cart->link;?>">
                            <?php echo $this->escape($cart->user_name)?>
                        </a>
                    <?php else:?>
                        <span class="order_name"><?php echo $this->escape($cart->user_name)?></span>
                    <?php endif;?>
                        
                    <?php if(!empty($cart->note)):?>
                        <a title="<?php echo $this->escape($cart->note);?>" class="note tooltip_label" href="javascript:void(0)"></a>
                    <?php endif;?>
                </div>
            </td>
            <td>
                <div class="order_info">
                    <span class="send_time"><?php echo date($this->translate("FORMAT_DATE"), $cart->time_sent);?></span>
                </div>
            </td>
            <td>
                <div class="order_info align_right">
                    <span class="total_price">
                        <?php echo Core_Util::formatPrice($this->store->unit_code, $cart->total_price);?>
                    </span>
                    <span><?php echo $this->store->getCurrency()?></span>
                </div>
            </td>
            <td>
                <select name="action" class="cart_action">
                    <option value="" selected="selected"><?php echo $this->translate('LABEL_SELECT_ACTION')?></option>
                    <option value="<?php echo $this->url(array_merge(array('action' => 'detail', 'id' => $cart->id), $this->extra_values['search_params']));?>">
                        <?php echo $this->translate('LABEL_LOWER_ACTION_DETAIL')?>
                    </option>
                    <?php if($cart->status != Core_Model_DbTable_Carts::STATUS_UNREAD):?>
                    <option value="<?php echo $this->url(array_merge(array('action' => 'mark', 'id_carts' => $cart->id, 'to_status' => Core_Model_DbTable_Carts::STATUS_UNREAD), $this->extra_values['search_params']));?>">
                        <?php echo $this->translate('LABEL_LOWER_ACTION_UNREAD')?>
                    </option>
                    <?php endif;?>
                    <?php if($cart->status != Core_Model_DbTable_Carts::STATUS_READ):?>
                    <option value="<?php echo $this->url(array_merge(array('action' => 'mark', 'id_carts' => $cart->id, 'to_status' =>Core_Model_DbTable_Carts::STATUS_READ), $this->extra_values['search_params']))?>">
                        <?php echo $this->translate('LABEL_LOWER_ACTION_READ')?>
                    </option>
                    <?php endif;?>
                    <?php if($cart->status != Core_Model_DbTable_Carts::STATUS_RESOLVED):?>
                    <option value="<?php echo $this->url(array_merge(array('action' => 'mark', 'id_carts' => $cart->id, 'to_status' =>Core_Model_DbTable_Carts::STATUS_RESOLVED), $this->extra_values['search_params']))?>">
                        <?php echo $this->translate('LABEL_LOWER_ACTION_RESOLVE')?>
                    </option>
                    <?php endif;?>
                    <?php if($cart->status != Core_Model_DbTable_Carts::STATUS_DELETE):?>
                    <option value="<?php echo $this->url(array_merge(array('action' => 'mark', 'id_carts' => $cart->id, 'to_status' =>Core_Model_DbTable_Carts::STATUS_DELETE), $this->extra_values['search_params']))?>">
                        <?php echo $this->translate('LABEL_LOWER_ACTION_DELETE')?>
                    </option>
                    <?php endif;?>
                </select>			
            </td>
        </tr>
        <?php endforeach;?>
    </tbody>
</table>
<?php echo $this->paginationControl(
		$this->paginator,
		'Sliding',
		'paginatorControl.phtml',
        array('search_params' => $this->extra_values['search_params'])
	);
?>
<?php else:?>
<div class="empty_items">
    <?php echo $this->translate('THERE_IS_NO_ANY_CARTS');?>
</div>
<?php endif; ?>
<script type="text/javascript">
    $(".tooltip_label").tipsy();
    $(".date").datepicker({ altFormat: "yy-mm-dd" });
</script>
